<?php
final class Controller_Album extends Controller{
    protected function Acquiescent(){
        $id=Route::GetArguments('id');
        if(!is_numeric($id)){
            header("HTTP/1.0 604 Internal Server Error!");
            return;
        }
        #类别
        $data=Database::GetRows('select * from app_album_class order by ID asc');
        Template::Assign('AlbumClassData',$data);
        #相册
        $data=Database::GetRows('select * from app_album where Class=? order by ID desc',
            array(
                $id
            ),
            array(
                'CurrentPage'=>Route::GetArguments('page'),
                'PageSize'=>18
            )
        );
        Template::Assign('AlbumData',$data);
        #相册所在类别
        $data=Database::GetRowByValue('app_album_class','ID',$id);
        if($data){
            Template::Assign('AlbumClassName',$data['Name']);
        }
        Template::Display('show/index2.html');
    }

    protected function Classes(){
        $data=Database::GetRows('select * from app_album_class order by ID asc');
        Template::Assign('AlbumClassData',$data);
        Template::Display('show/index.html');
    }

    protected function Picture(){
        #类别数据
        $data=Database::GetRows('select * from app_album_class order by ID asc');
        Template::Assign('AlbumClassData',$data);
        #照片数据
        $id=Route::GetArguments('id'); //相册ID
        if(!is_numeric($id)){
            return;
        }
        $data=Database::GetRows('select * from app_album_picture where Album=? order by ID asc',array(
            $id
        ));
        Template::Assign('PictureData',$data);
        #相册名称
        $data=Database::GetRowByValue('app_album','ID',$id);
        Template::Assign('AlbumName',$data['Name']);
        #类别名称和ID
        if($data){
            $data=Database::GetRowByValue('app_album_class','ID',$data['Class']);
            Template::Assign('AlbumClassID',$data['ID']);
            Template::Assign('AlbumClassName',$data['Name']);
        }
        #上一相册
        $data=Database::GetRows('select * from app_album where ID<? order by ID desc limit 0,1',array($id));
        if($data){
            Template::Assign('PreviousAlbumID',$data[0]['ID']);
        }
        #下一相册
        $data=Database::GetRows('select * from app_album where ID>? order by ID asc limit 0,1',array($id));
        if($data){
            Template::Assign('NextAlbumID',$data[0]['ID']);
        }
        #渲染模板
        Template::Display('show/show.html');
    }
}
?>